const Sequelize = require("sequelize");
const sequelize = require("../config/database");
const City = require("./City");
const Sight = require("./Sight");
const Comment = require("./Comment");
const User = require("./User");
const Spot = sequelize.define(
  "spot",
  {
    id: {
      type: Sequelize.INTEGER,
      autoIncrement: true,
      primaryKey: true,
    },
    name: {
      type: Sequelize.STRING,
      allowNull: false,
      notNull: true,
    },
    description: {
      type: Sequelize.TEXT,
    },
    image: {
      type: Sequelize.STRING,
    },
    userId: {
      type: Sequelize.INTEGER,
      allowNull: false,
    },
    cityId: {
      type: Sequelize.INTEGER,
      references: {
        model: City, // city 表
        key: "id", // city表的主键
      },
    },
    sightId: {
      type: Sequelize.INTEGER,
      references: {
        model: Sight,
        key: "id",
      },
    },
  },
  {
    paranoid: false,
  }
);

// Spot.belongsTo(City);
// Spot.belongsTo(User);
// Spot.belongsTo(City);
// City.hasMany(Spot);
// Spot.hasMany(Comment);
Spot.belongsTo(City);
Spot.belongsTo(Sight);
module.exports = Spot;
